package com.wolfking.jeesite.freemarker.method;

import com.wolfking.jeesite.freemarker.FreemarkerMethod;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.text.SimpleDateFormat;
import java.util.List;

@FreemarkerMethod("dateToTimeStamp")
public class DateToTimeStampMethod implements TemplateMethodModelEx {

    @Override
    public Object exec(List list) throws TemplateModelException {
        String dateStr = list.get(0).toString();
        String format = list.get(1).toString();
        try {
            return new SimpleDateFormat(format).parse(dateStr).getTime();
        } catch (Exception e) {
            return -1;
        }
    }
}
